﻿<UserControl x:Class="Samba.Modules.MenuModule.MenuItemPropertyGroupView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:Common="clr-namespace:Samba.Presentation.Common;assembly=Samba.Presentation.Common"
     mc:Ignorable="d">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto" />
            <ColumnDefinition Width="auto" />
        </Grid.ColumnDefinitions>
        <StackPanel>
            <Label>
                <LocText ResourceIdentifierKey="ModifierGroupName" Suffix=":"/>
            </Label>
            <TextBox HorizontalAlignment="Left" MinWidth="200" Text="{Binding Name,Mode=TwoWay}" />
            <CheckBox Margin="5,5,0,0" Content="{LocText SingleSelection}"
                 IsChecked="{Binding SingleSelection}" />
            <CheckBox Margin="5,5,0,0" Content="{LocText MultipleSelection}"
                 IsChecked="{Binding MultipleSelection}" />
            <CheckBox Margin="5,5,0,0" Content="{LocText AddPropertyPriceToProductPrice}"
                 IsChecked="{Binding CalculateWithParentPrice}" />
            <CheckBox Margin="5,5,0,0" IsChecked="{Binding ForceValue}">
                <LocText ResourceIdentifierKey="SelectionRequired" />
            </CheckBox>
            <Label>
                <LocText ResourceIdentifierKey="GroupTag" Suffix=":"/>
            </Label>
            <TextBox HorizontalAlignment="Left" MinWidth="100" Text="{Binding GroupTag,Mode=TwoWay}" />
            <GroupBox Header="{LocText POSView}" Padding="5"
                 HorizontalAlignment="Left" Margin="0,5,0,0">
                <UniformGrid HorizontalAlignment="Left">
                    <Label>
                        <LocText ResourceIdentifierKey="ColumnCount" Suffix=":"/>
                    </Label>
                    <Common:FilteredTextBox Type="Digits" Margin="0,0,0,2" HorizontalAlignment="Left"
                         MinWidth="50" Text="{Binding ColumnCount}">
                    </Common:FilteredTextBox>
                    <Label>
                        <LocText ResourceIdentifierKey="ButtonHeight" Suffix=":"/>
                    </Label>
                    <Common:FilteredTextBox Type="Digits" Margin="0,0,0,2" HorizontalAlignment="Left"
                         MinWidth="50" Text="{Binding ButtonHeight}">
                    </Common:FilteredTextBox>
                </UniformGrid>
            </GroupBox>
            <GroupBox Header="{LocText TerminalView}" Padding="5"
                 Margin="0,5,0,0" HorizontalAlignment="Left">
                <UniformGrid HorizontalAlignment="Left">
                    <Label>
                        <LocText ResourceIdentifierKey="ColumnCount" Suffix=":"/>
                    </Label>
                    <Common:FilteredTextBox Type="Digits" Margin="0,0,0,2" HorizontalAlignment="Left"
                         MinWidth="50" Text="{Binding TerminalColumnCount}">
                    </Common:FilteredTextBox>
                    <Label>
                        <LocText ResourceIdentifierKey="ButtonHeight" Suffix=":"/>
                    </Label>
                    <Common:FilteredTextBox Type="Digits" Margin="0,0,0,2" HorizontalAlignment="Left"
                         MinWidth="50" Text="{Binding TerminalButtonHeight}">
                    </Common:FilteredTextBox>
                </UniformGrid>
            </GroupBox>
        </StackPanel>
        <Grid Grid.Column="1" Margin="20,0" Grid.RowSpan="2">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>

            <Label Grid.Row="0" Grid.ColumnSpan="2">
                <LocText ResourceIdentifierKey="Modifiers" Suffix=":"/>
            </Label>

            <DataGrid Grid.Row="1" Grid.Column="0" ItemsSource="{Binding Properties}" SelectedItem="{Binding SelectedProperty, Mode=TwoWay}"
                      HorizontalAlignment="Left" GridLinesVisibility="None" RowHeaderWidth="0" Margin="0,3"
                      VerticalAlignment="Top" MinHeight="100"
                      AutoGenerateColumns="False" CanUserSortColumns="False" 
                      Background="{StaticResource {x:Static SystemColors.WindowBrushKey}}"
                      CellEditEnding="DataGrid_CellEditEnding">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="{LocText Modifier}"
                             MinWidth="100" Binding="{Binding Name}" />
                    <DataGridTemplateColumn Header="{LocText Product}"
                             MinWidth="100">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Margin="3" Text="{Binding MenuItem.Name}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                        <DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <Grid FocusManager.FocusedElement="{Binding ElementName=cb}">
                                    <ComboBox Name="cb" IsEditable="True" DisplayMemberPath="Name" ItemsSource="{Binding MenuItems}"
                                             SelectedItem="{Binding MenuItem}" />
                                </Grid>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellEditingTemplate>
                    </DataGridTemplateColumn>

                    <DataGridTextColumn Header="{LocText Price}" Binding="{Binding Path=Price,StringFormat='#,#0.00'}" CellStyle="{StaticResource RightAlignedCellStyle}" />
                </DataGrid.Columns>
                <DataGrid.ContextMenu>
                    <ContextMenu>
                        <MenuItem Command="{Binding AddPropertyCommand}" Header="{Binding AddPropertyCommand.Caption}" />
                        <MenuItem Command="{Binding DeletePropertyCommand}" Header="{Binding DeletePropertyCommand.Caption}" />
                    </ContextMenu>
                </DataGrid.ContextMenu>
            </DataGrid>
            <StackPanel Margin="10" Grid.Row="1" Grid.Column="1">
                <TextBlock Margin="2,3">
                        <Hyperlink Command="{Binding AddPropertyCommand}">
                            <TextBlock Text="{Binding Path=AddPropertyCommand.Caption}" />
                        </Hyperlink>
                    </TextBlock>
                <TextBlock Margin="2,3">
                        <Hyperlink Command="{Binding DeletePropertyCommand}">
                            <TextBlock Text="{Binding Path=DeletePropertyCommand.Caption}" />
                        </Hyperlink>
                    </TextBlock>
            </StackPanel>

        </Grid>
        <StackPanel Grid.Row="1">
            <Button HorizontalAlignment="Left" Margin="0,10" MinWidth="70" Content="{Binding SaveCommand.Caption}"
                 Command="{Binding SaveCommand}" />
            <Label Content="{Binding Error}" Foreground="Red" />
        </StackPanel>
    </Grid>
</UserControl>